namespace KPIS.GERP.Models.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class update0030 : DbMigration
    {
        public override void Up()
        {
            DropForeignKey("dbo.HrmPsEmpPositionHistory", "EmpId", "dbo.hrm_ps_employees");
            //DropForeignKey("dbo.HrmPsEmpPositionHistory", "CmdDtlsId", "dbo.hrm_ps_command_dtls");
            DropForeignKey("dbo.HrmPsEmpPositionHistory", "CmdClassId", "dbo.hrm_mp_classes");
            //DropForeignKey("dbo.HrmPsEmpPositionHistory", "CmdJobSiteId", "dbo.hrm_mp_job_sites");
            DropForeignKey("dbo.HrmPsEmpPositionHistory", "CmdFieldId", "dbo.HrmFieldPosition");
            //DropForeignKey("dbo.HrmPsEmpPositionHistory", "CmdExecId", "dbo.hrm_ps_commands");
            DropForeignKey("dbo.HrmPsEmpPositionHistory", "ClassId", "dbo.hrm_mp_classes");
            //DropForeignKey("dbo.HrmPsEmpPositionHistory", "JobSiteId", "dbo.hrm_mp_job_sites");
            DropForeignKey("dbo.HrmPsEmpPositionHistory", "MoveId", "dbo.HrmEsMoveRequest");
            //DropForeignKey("dbo.HrmPsEmpPositionHistory", "CmdTypeId", "dbo.hrm_ps_command_types");
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "EmpId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "CmdDtlsId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "CmdClassId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "CmdJobSiteId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "CmdFieldId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "CmdExecId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "ClassId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "JobSiteId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "MoveId" });
            DropIndex("dbo.HrmPsEmpPositionHistory", new[] { "CmdTypeId" });
            try
            {
                RenameTable("hrm_ps_emp_position_histories", "hrm_ps_emp_position_histories___unused");
            }catch
            {
            }
            CreateTable(
                "dbo.hrm_ps_emp_position_histories",
                c => new
                    {
                        pos_his_seq = c.Int(nullable: false, identity: true),
                        emp_seq = c.Int(),
                        start_date = c.DateTime(),
                        end_date = c.DateTime(),
                        cmd_dtls_seq = c.Int(),
                        cmd_ref_no = c.String(),
                        cmd_date = c.DateTime(),
                        cmd_name = c.String(),
                        cmd_pos_ref = c.String(),
                        cmd_pos_name = c.String(),
                        cmd_class_seq = c.Int(),
                        cmd_class_name = c.String(),
                        cmd_job_site_seq = c.Int(),
                        cmd_job_site_name = c.String(),
                        cmd_working_job_site_name = c.String(),
                        cmd_dep_name = c.String(),
                        cmd_mis_name = c.String(),
                        cmd_field_seq = c.Int(),
                        cmd_field_name = c.String(),
                        cmd_exec_seq = c.Int(),
                        cmd_exec_name = c.String(),
                        cmd_salary = c.Double(),
                        cmd_salary_position = c.Double(),
                        salary = c.Double(),
                        pos_ref = c.String(),
                        pos_name = c.String(),
                        class_seq = c.Int(),
                        class_name = c.String(),
                        job_site_seq = c.Int(),
                        job_site_name = c.String(),
                        move_seq = c.Int(),
                        remarks = c.String(),
                        record_status = c.String(),
                        created_by = c.Int(),
                        created_when = c.DateTime(),
                        updated_by = c.Int(),
                        updated_when = c.DateTime(),
                        cmd_type_seq = c.Int(),
                        his_type = c.String(),
                        working_job_site_name = c.String(),
                        department_name = c.String(),
                        ministry_name = c.String(),
                        field_name = c.String(),
                        exec_name = c.String(),
                    })
                .PrimaryKey(t => t.pos_his_seq)
                .ForeignKey("dbo.hrm_ps_employees", t => t.emp_seq)
                .ForeignKey("dbo.hrm_ps_command_dtls", t => t.cmd_dtls_seq)
                .ForeignKey("dbo.hrm_mp_classes", t => t.cmd_class_seq)
                .ForeignKey("dbo.hrm_mp_job_sites", t => t.cmd_job_site_seq)
                .ForeignKey("dbo.HrmFieldPosition", t => t.cmd_field_seq)
                .ForeignKey("dbo.hrm_ps_commands", t => t.cmd_exec_seq)
                .ForeignKey("dbo.hrm_mp_classes", t => t.class_seq)
                .ForeignKey("dbo.hrm_mp_job_sites", t => t.job_site_seq)
                .ForeignKey("dbo.HrmEsMoveRequest", t => t.move_seq)
                .ForeignKey("dbo.hrm_ps_command_types", t => t.cmd_type_seq)
                .Index(t => t.emp_seq)
                .Index(t => t.cmd_dtls_seq)
                .Index(t => t.cmd_class_seq)
                .Index(t => t.cmd_job_site_seq)
                .Index(t => t.cmd_field_seq)
                .Index(t => t.cmd_exec_seq)
                .Index(t => t.class_seq)
                .Index(t => t.job_site_seq)
                .Index(t => t.move_seq)
                .Index(t => t.cmd_type_seq);
            
            DropTable("dbo.HrmPsEmpPositionHistory");
        }
        
        public override void Down()
        {
            CreateTable(
                "dbo.HrmPsEmpPositionHistory",
                c => new
                    {
                        PosHisId = c.Int(nullable: false, identity: true),
                        EmpId = c.Int(),
                        StartDate = c.DateTime(),
                        EndDate = c.DateTime(),
                        CmdDtlsId = c.Int(),
                        CmdRefNo = c.String(),
                        CmdDate = c.DateTime(),
                        CmdName = c.String(),
                        CmdPosRef = c.String(),
                        CmdPosName = c.String(),
                        CmdClassId = c.Int(),
                        CmdClassName = c.String(),
                        CmdJobSiteId = c.Int(),
                        CmdJobSiteName = c.String(),
                        CmdWorkingJobSiteName = c.String(),
                        CmdDepName = c.String(),
                        CmdMisName = c.String(),
                        CmdFieldId = c.Int(),
                        CmdFieldName = c.String(),
                        CmdExecId = c.Int(),
                        CmdExecName = c.String(),
                        CmdSalary = c.Double(),
                        CmdSalaryPosition = c.Double(),
                        Salary = c.Double(),
                        PosRef = c.String(),
                        PosName = c.String(),
                        ClassId = c.Int(),
                        ClassName = c.String(),
                        JobSiteId = c.Int(),
                        JobSiteName = c.String(),
                        MoveId = c.Int(),
                        Remarks = c.String(),
                        RecordStatus = c.String(),
                        CreatedBy = c.Int(),
                        CreatedWhen = c.DateTime(),
                        UpdatedBy = c.Int(),
                        UpdatedWhen = c.DateTime(),
                        CmdTypeId = c.Int(),
                        HisType = c.String(),
                        WorkingJobSiteName = c.String(),
                        DepartmentName = c.String(),
                        MinistryName = c.String(),
                        FieldName = c.String(),
                        ExecName = c.String(),
                    })
                .PrimaryKey(t => t.PosHisId);
            
            DropIndex("dbo.hrm_ps_emp_position_histories", new[] { "cmd_type_seq" });
            DropIndex("dbo.hrm_ps_emp_position_histories", new[] { "move_seq" });
            DropIndex("dbo.hrm_ps_emp_position_histories", new[] { "job_site_seq" });
            DropIndex("dbo.hrm_ps_emp_position_histories", new[] { "class_seq" });
            DropIndex("dbo.hrm_ps_emp_position_histories", new[] { "cmd_exec_seq" });
            DropIndex("dbo.hrm_ps_emp_position_histories", new[] { "cmd_field_seq" });
            DropIndex("dbo.hrm_ps_emp_position_histories", new[] { "cmd_job_site_seq" });
            DropIndex("dbo.hrm_ps_emp_position_histories", new[] { "cmd_class_seq" });
            DropIndex("dbo.hrm_ps_emp_position_histories", new[] { "cmd_dtls_seq" });
            DropIndex("dbo.hrm_ps_emp_position_histories", new[] { "emp_seq" });
            DropForeignKey("dbo.hrm_ps_emp_position_histories", "cmd_type_seq", "dbo.hrm_ps_command_types");
            DropForeignKey("dbo.hrm_ps_emp_position_histories", "move_seq", "dbo.HrmEsMoveRequest");
            DropForeignKey("dbo.hrm_ps_emp_position_histories", "job_site_seq", "dbo.hrm_mp_job_sites");
            DropForeignKey("dbo.hrm_ps_emp_position_histories", "class_seq", "dbo.hrm_mp_classes");
            DropForeignKey("dbo.hrm_ps_emp_position_histories", "cmd_exec_seq", "dbo.hrm_ps_commands");
            DropForeignKey("dbo.hrm_ps_emp_position_histories", "cmd_field_seq", "dbo.HrmFieldPosition");
            DropForeignKey("dbo.hrm_ps_emp_position_histories", "cmd_job_site_seq", "dbo.hrm_mp_job_sites");
            DropForeignKey("dbo.hrm_ps_emp_position_histories", "cmd_class_seq", "dbo.hrm_mp_classes");
            DropForeignKey("dbo.hrm_ps_emp_position_histories", "cmd_dtls_seq", "dbo.hrm_ps_command_dtls");
            DropForeignKey("dbo.hrm_ps_emp_position_histories", "emp_seq", "dbo.hrm_ps_employees");
            DropTable("dbo.hrm_ps_emp_position_histories");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "CmdTypeId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "MoveId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "JobSiteId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "ClassId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "CmdExecId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "CmdFieldId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "CmdJobSiteId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "CmdClassId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "CmdDtlsId");
            CreateIndex("dbo.HrmPsEmpPositionHistory", "EmpId");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "CmdTypeId", "dbo.hrm_ps_command_types", "cmd_type_seq");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "MoveId", "dbo.HrmEsMoveRequest", "ReqId");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "JobSiteId", "dbo.hrm_mp_job_sites", "job_site_seq");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "ClassId", "dbo.hrm_mp_classes", "class_seq");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "CmdExecId", "dbo.hrm_ps_commands", "cmd_seq");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "CmdFieldId", "dbo.HrmFieldPosition", "FieldPosId");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "CmdJobSiteId", "dbo.hrm_mp_job_sites", "job_site_seq");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "CmdClassId", "dbo.hrm_mp_classes", "class_seq");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "CmdDtlsId", "dbo.hrm_ps_command_dtls", "cmd_dtls_seq");
            AddForeignKey("dbo.HrmPsEmpPositionHistory", "EmpId", "dbo.hrm_ps_employees", "emp_seq");
        }
    }
}
